﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HF.Framework.DataClientDBAgent;
using HF.Framework.SqlDataContract;
using HF.Framework.Web;
using HF.WorkFlow.Const;
using HF.Business.Sale;
using HF.Business.Common;


public partial class SaleLoseMgr : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            YYSimpleCalendar1.Text = BusinessComm.GetNowDate();
            YYSimpleCalendar2.Text = BusinessComm.GetAddDaysDate(30);
            initData();
            
        }
    }
    //private void initData()
    //{
        
    //    DataTable dt = SaleLose.QueryByDate(YYSimpleCalendar1.Text, YYSimpleCalendar2.Text);
    //    gvSaleLose.DataSource = dt;
    //    gvSaleLose.DataBind();
    //}

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (cbxBillCode.Checked == false && cbxDatetime.Checked == false)
        {
            WorkDialog.ShowMessage(this, "请选择查询条件!!");
            return;
        }
        initData();

    }
    private void initData()
    {
        string sql = "select * from Sale_V_Lose where 1=1 and ";
        SqlDataItem sqlItem = new SqlDataItem();
        if (cbxBillCode.Checked==true)
        {
            sql = sql + "Bill_Code like @billcode  and ";
            sqlItem.AppendParameter("@billcode", "%" + tbxBillCode.Text + "%");
        }
        else
        {
            sql = sql + "1=@billcode and ";
            sqlItem.AppendParameter("@billcode", 1,typeof(int));
        }
        if (cbxDatetime.Checked==true)
        {
            sql = sql + "Bill_CreateDate >=@begintime  and ";
            sql = sql + "Bill_CreateDate <=@endtime  ";
            sqlItem.AppendParameter("@begintime", YYSimpleCalendar1.Text);
            sqlItem.AppendParameter("@endtime", YYSimpleCalendar2.Text);
        }
        else
        {
            sql = sql + "1=@begintime and ";
            sql = sql + "1=@endtime  ";
            sqlItem.AppendParameter("@begintime", 1,typeof(int));
            sqlItem.AppendParameter("@endtime", 1,typeof(int));
 
        }
        sqlItem.CommandText = sql;
        ClientDBAgent agent = new ClientDBAgent();
        DataTable dt =agent.ExecuteDataTable(sqlItem);        
        gvSaleLose.DataSource = dt;
        gvSaleLose.DataBind();
    }
    protected void btnProduct_Click(object sender, EventArgs e)
    {
        
    }
    protected void lbtnProduct_Click(object sender, EventArgs e)
    {

    }
    double sumMoney = 0.00;//单据金额
    protected void gvSaleLose_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        if (e.Row.RowIndex >= 0)
        {
            sumMoney += Convert.ToDouble(e.Row.Cells[2].Text);
            
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[1].Text = "合计金额:";
            e.Row.Cells[2].Text = sumMoney.ToString();
           


        }
    }
}
